import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios'
import { MessageBox } from 'element-ui';





const instance = axios.create({
  // baseURL:' ', //默认浏览器地址
  timeout:8000, //请求超时时间
  // headers:{'authorization':localStorage.getItem("authorization")}
});


instance.interceptors.request.use((config)=>{
  // 所有请求发送之前 在 请求头上挂载token
  config.headers.authorization=localStorage.getItem("authorization") //（在上面已经挂载了） 
  // config 请求生成出 的 实例
  return config
})
instance.interceptors.response.use((response)=>{

  if(response.data.code==401){
     MessageBox.alert("登录已过期,请重新登录","错误",{
      type:'error',
      confirmButtonText:'去登录'
     }).then(()=>{
      localStorage.removeItem("authorization");
     router.push('/four').then(() => {
        window.location.reload(); 
      });

     })

  }
  return response

})

Vue.config.productionTip = false
Vue.use(ElementUI);
Vue.prototype.$axios = instance

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
